package edu.scau.misp.backend_module.controller;

import edu.scau.misp.backend_module.core.domain.AjaxResult;
import edu.scau.misp.backend_module.domain.Deal;
import edu.scau.misp.backend_module.domain.Dish;
import edu.scau.misp.backend_module.service.IDealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping({"deal"})
public class DealController {
    @Autowired
    private IDealService dealService;
    @GetMapping("/sn/{dealSn}")
    public AjaxResult getDishBySn(@PathVariable("dealSn") Long dealSn) {
        return AjaxResult.success(dealService.getDealBySn(dealSn));
    }

    @GetMapping("/listAll")
    public AjaxResult listAllDeal(){
        return AjaxResult.success(dealService.listAllDeal());
    }

    @GetMapping("/list")
    public AjaxResult list(Deal deal) {
        List<Deal> list = dealService.selectDealList(deal);
        return AjaxResult.success(list);
    }

    @PostMapping
    public AjaxResult add(@RequestBody Deal deal) {
        int rows = dealService.insertDeal(deal);
        return rows > 0 ? AjaxResult.success("添加套餐成功") : AjaxResult.error("添加套餐失败");
    }
    @PutMapping
    public AjaxResult edit(@RequestBody Deal deal) {
        int rows = dealService.updateDeal(deal);
        return rows > 0 ? AjaxResult.success("修改套餐成功") : AjaxResult.error("修改套餐失败");
    }
    @DeleteMapping("/{dealId}")
    public AjaxResult remove(@PathVariable("dealId") Long dealId) {
        int rows = dealService.deleteDealById(dealId);
        return rows > 0 ? AjaxResult.success("删除套餐成功") : AjaxResult.error("删除套餐失败");
    }



}
